from django.db import models
import os


# Create your models here.
class WeiboModel(models.Model):
    """
    微博帖子数据
    """
    text = models.TextField(blank=True, null=True)
    topic = models.CharField(max_length=2048, blank=True, null=True)
    num1 = models.IntegerField(blank=True, null=True)
    num2 = models.IntegerField(blank=True, null=True)
    num3 = models.IntegerField(blank=True, null=True)
    date = models.CharField(max_length=255, blank=True, null=True)
    tool = models.CharField(max_length=255, blank=True, null=True)
    flag = models.CharField(max_length=32, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'weibo'


class CommentModel(models.Model):
    """
    评论数据模型
    """
    content = models.TextField(blank=True, null=True)
    ip_location = models.CharField(max_length=32, blank=True, null=True)
    followers_count = models.IntegerField(blank=True, null=True)
    friends_count = models.IntegerField(blank=True, null=True)
    like_counts = models.IntegerField(blank=True, null=True)
    created_at = models.CharField(max_length=64, blank=True, null=True)
    gender = models.CharField(max_length=16, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'comment'


def user_directory_path(instance, filename):
    name = 'user_{}'.format(instance.uploader)
    return os.path.join(name, filename)


class UserUpload(models.Model):
    """
    用户文件上传模型
    """
    title = models.CharField(max_length=128, blank=True)
    file = models.FileField(upload_to=user_directory_path, blank=True, null=True, max_length=1024)
    timestamp = models.DateTimeField(auto_now_add=True)
    uploader = models.CharField(max_length=8)

    class Meta:
        db_table = "upload"
        verbose_name = "文件上传"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.title
